<?php
/*
 * Author:  Somnath Shinde- soma.shinde@gmail.com Mobile No:- 9423792564
 * 
 * Create Date: 
 * 
 * Version of MYSQL_to_PHP: 1.1
 * 
 * Ranzani( YZ'S );
 * 
 */
require_once 'Base/BasePatientDetails.class.php';

Class PatientDetails {

	public function  __construct() {
			if( true == isset( $_SERVER['connection'] ) ) {
				$this->connection = $_SERVER['connection'];
			}
	}

	
	/*******************************************************************************************
	******************************** Fetch Functions *******************************************
	*******************************************************************************************/

	public function fetchSql( $strSql ) {
		$result = $this->connection->RunQuery( $strSql );
		$arrobjPatientDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientDetails = new BasePatientDetails();
			$objPatientDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientDetails->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objPatientDetails->setMonthlyIncome( ( true == isset( $row["monthly_income"] ) ) ? $row["monthly_income"] : 'NULL' );
			$objPatientDetails->setRelievedDate( ( true == isset( $row["relieved_date"] ) ) ? $row["relieved_date"] : 'NULL' );
			$objPatientDetails->setDischargeDate( ( true == isset( $row["discharge_date"] ) ) ? $row["discharge_date"] : 'NULL' );
			$objPatientDetails->setAdmissionDate( ( true == isset( $row["admission_date"] ) ) ? $row["admission_date"] : 'NULL' );
			$objPatientDetails->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objPatientDetails->setBeedNumber( ( true == isset( $row["beed_number"] ) ) ? $row["beed_number"] : 'NULL' );
			$objPatientDetails->setCasePaperCount( ( true == isset( $row["case_paper_count"] ) ) ? $row["case_paper_count"] : 'NULL' );
			$objPatientDetails->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objPatientDetails->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objPatientDetails->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objPatientDetails->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjPatientDetails, $objPatientDetails );
		}
		return $arrobjPatientDetails;
	}
	public function fetchAllPatientDetails() {
		$result = $this->connection->RunQuery("SELECT * FROM PATIENT_DETAILS");
		$arrobjPatientDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientDetails = new BasePatientDetails();
			$objPatientDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientDetails->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objPatientDetails->setMonthlyIncome( ( true == isset( $row["monthly_income"] ) ) ? $row["monthly_income"] : 'NULL' );
			$objPatientDetails->setRelievedDate( ( true == isset( $row["relieved_date"] ) ) ? $row["relieved_date"] : 'NULL' );
			$objPatientDetails->setDischargeDate( ( true == isset( $row["discharge_date"] ) ) ? $row["discharge_date"] : 'NULL' );
			$objPatientDetails->setAdmissionDate( ( true == isset( $row["admission_date"] ) ) ? $row["admission_date"] : 'NULL' );
			$objPatientDetails->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objPatientDetails->setBeedNumber( ( true == isset( $row["beed_number"] ) ) ? $row["beed_number"] : 'NULL' );
			$objPatientDetails->setCasePaperCount( ( true == isset( $row["case_paper_count"] ) ) ? $row["case_paper_count"] : 'NULL' );
			$objPatientDetails->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objPatientDetails->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objPatientDetails->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objPatientDetails->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjPatientDetails, $objPatientDetails);
		}
		return $arrobjPatientDetails;
	}
	public function fetchAllPatientDetailsByIds( $arrintIds ) {
		$result = $this->connection->RunQuery("SELECT * FROM PATIENT_DETAILS WHERE id IN ( implode( "," $arrintIds ) " );
		$arrobjPatientDetails = array();
		while( $row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientDetails->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objPatientDetails->setMonthlyIncome( ( true == isset( $row["monthly_income"] ) ) ? $row["monthly_income"] : 'NULL' );
			$objPatientDetails->setRelievedDate( ( true == isset( $row["relieved_date"] ) ) ? $row["relieved_date"] : 'NULL' );
			$objPatientDetails->setDischargeDate( ( true == isset( $row["discharge_date"] ) ) ? $row["discharge_date"] : 'NULL' );
			$objPatientDetails->setAdmissionDate( ( true == isset( $row["admission_date"] ) ) ? $row["admission_date"] : 'NULL' );
			$objPatientDetails->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objPatientDetails->setBeedNumber( ( true == isset( $row["beed_number"] ) ) ? $row["beed_number"] : 'NULL' );
			$objPatientDetails->setCasePaperCount( ( true == isset( $row["case_paper_count"] ) ) ? $row["case_paper_count"] : 'NULL' );
			$objPatientDetails->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objPatientDetails->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objPatientDetails->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objPatientDetails->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
			array_push( $arrobjPatientDetails, $objPatientDetails );
		}
		return $arrobjPatientDetails;
	}

	public function fetchPatientDetailsById( $intId ) {
		$result = $this->connection->RunQuery( "SELECT * FROM PATIENT_DETAILS WHERE id = " . $intId );
			$objPatientDetails = NULL;
		while($row = $result->fetch_array( MYSQLI_ASSOC ) ) {
			$objPatientDetails = new BasePatientDetails();
			$objPatientDetails->setId( ( true == isset( $row["id"] ) ) ? $row["id"] : 'NULL' );
			$objPatientDetails->setPatientId( ( true == isset( $row["patient_id"] ) ) ? $row["patient_id"] : 'NULL' );
			$objPatientDetails->setMonthlyIncome( ( true == isset( $row["monthly_income"] ) ) ? $row["monthly_income"] : 'NULL' );
			$objPatientDetails->setRelievedDate( ( true == isset( $row["relieved_date"] ) ) ? $row["relieved_date"] : 'NULL' );
			$objPatientDetails->setDischargeDate( ( true == isset( $row["discharge_date"] ) ) ? $row["discharge_date"] : 'NULL' );
			$objPatientDetails->setAdmissionDate( ( true == isset( $row["admission_date"] ) ) ? $row["admission_date"] : 'NULL' );
			$objPatientDetails->setWardId( ( true == isset( $row["ward_id"] ) ) ? $row["ward_id"] : 'NULL' );
			$objPatientDetails->setBeedNumber( ( true == isset( $row["beed_number"] ) ) ? $row["beed_number"] : 'NULL' );
			$objPatientDetails->setCasePaperCount( ( true == isset( $row["case_paper_count"] ) ) ? $row["case_paper_count"] : 'NULL' );
			$objPatientDetails->setCreatedBy( ( true == isset( $row["created_by"] ) ) ? $row["created_by"] : 'NULL' );
			$objPatientDetails->setCreatedOn( ( true == isset( $row["created_on"] ) ) ? $row["created_on"] : 'NULL' );
			$objPatientDetails->setUpdatedBy( ( true == isset( $row["updated_by"] ) ) ? $row["updated_by"] : 'NULL' );
			$objPatientDetails->setUpdatedOn( ( true == isset( $row["updated_on"] ) ) ? $row["updated_on"] : 'NULL' );
		}
		return $objPatientDetails;
	}

	public function GetKeysOrderBy($column, $order){
		$keys = array(); $i = 0;
		$result = $this->connection->RunQuery("SELECT id from patient_details order by $column $order");
			while($row = $result->fetch_array(MYSQLI_ASSOC)){
				$keys[$i] = $row["id"];
				$i++;
			}
	return $keys;
	}

	public function endPatientDetails(){
		$this->connection->CloseMysql();
	}

}